package com.ruoyi.security.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.security.domain.AfCheckLog;
import com.ruoyi.security.domain.vo.DeviceInfoVo;
import com.ruoyi.security.service.IAfCheckLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 设备年检记录Controller
 *
 * @author cjie
 * @date 2022-06-20
 */
@Api(tags = " 设备年检记录")
@RestController
@RequestMapping("/afCheckLog")
public class AfCheckLogController extends BaseController {
    @Autowired
    private IAfCheckLogService afCheckLogService;

    /**
     * 查询设备年检记录列表
     */
    @ApiOperation(value="查询设备年检记录列表", notes="查询设备年检记录列表")
    @PreAuthorize(hasPermi = "security:afCheckLog:list")
    @GetMapping("/list")
    public TableDataInfo list(AfCheckLog afCheckLog) {
        startPage();
        List<AfCheckLog> list = afCheckLogService.selectAfCheckLogList(afCheckLog);
        return getDataTable(list);
    }

    @ApiOperation(value="查询设备列表", notes="查询设备列表")
    @PreAuthorize(hasPermi = "security:afCheckLog:list")
    @GetMapping("/deviceList")
    public AjaxResult deviceList(String moduleType) {
        List<DeviceInfoVo> list = afCheckLogService.selectDeviceList(moduleType);
        return AjaxResult.success(list);
    }

    /**
     * 导出设备年检记录列表
     */
    @ApiOperation(value="导出设备年检记录列表", notes="导出设备年检记录列表")
    @PreAuthorize(hasPermi = "security:afCheckLog:export")
    @Log(title = "设备年检记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AfCheckLog afCheckLog) throws IOException {
        List<AfCheckLog> list = afCheckLogService.selectAfCheckLogList(afCheckLog);
        ExcelUtil<AfCheckLog> util = new ExcelUtil<AfCheckLog>(AfCheckLog.class);
        util.exportExcel(response, list, "设备年检记录数据");
    }
    /**
     * 获取设备年检记录详细信息
     */
    @ApiOperation(value="获取设备年检记录详细信息", notes="获取设备年检记录详细信息")
    @PreAuthorize(hasPermi = "security:afCheckLog:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(afCheckLogService.selectAfCheckLogById(id));
    }

    /**
     * 新增设备年检记录
     */
    @ApiOperation(value="新增设备年检记录", notes="新增设备年检记录")
    @PreAuthorize(hasPermi = "security:afCheckLog:add")
    @Log(title = "设备年检记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AfCheckLog afCheckLog) {
        return toAjax(afCheckLogService.insertAfCheckLog(afCheckLog));
    }

    /**
     * 修改设备年检记录
     */
    @ApiOperation(value="修改设备年检记录", notes="修改设备年检记录")
    @PreAuthorize(hasPermi = "security:afCheckLog:edit")
    @Log(title = "设备年检记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AfCheckLog afCheckLog) {
        return toAjax(afCheckLogService.updateAfCheckLog(afCheckLog));
    }

    /**
     * 删除设备年检记录
     */
    @ApiOperation(value="删除设备年检记录", notes="删除设备年检记录")
    @ApiImplicitParam(name = "ids", value = "设备年检记录ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "security:afCheckLog:remove")
    @Log(title = "设备年检记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(afCheckLogService.deleteAfCheckLogByIds(ids));
    }
}
